package com.naire.modul.district.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import net.common.manager.SystemCodeManager;
import net.common.service.GeneralService;

import com.excel.analysis.ExcelBean;
import com.excel.analysis.ReaderExcel;
import com.naire.modul.district.dao.DistrictDao;
import com.naire.modul.district.dao.impl.DistrictDaoImpl;
import com.naire.modul.district.vo.DistrictVo;

/**
 * 
 * 
 * @author Administrator
 * 
 */
public class DistrictImportService extends GeneralService {

	private DistrictVo bean;

	@Override
	public void execute() throws Exception {
		List<DistrictVo> list = new ArrayList<DistrictVo>();
		File file = bean.getTemplate();
		ReaderExcel reader = new ReaderExcel(file);
		List<ExcelBean> ebs = reader.readRow();
		for(ExcelBean eb : ebs) {
			DistrictVo vo = new DistrictVo();
			vo.setArea_code(eb.getValueByKey("area_code"));
			vo.setDistrict_name(eb.getValueByKey("district_name"));
			vo.setDistrict_code(SystemCodeManager.createCode("0001", bean.getParent_code()));
			vo.setFlag(0);
			vo.setParent_code(bean.getParent_code());
			list.add(vo);
		}
		DistrictDao dao = new DistrictDaoImpl();
		dao.insert(list);
	}

	public void setBean(DistrictVo bean) {
		this.bean = bean;
	}


}
